const mongoose = require('mongoose');

const leaveSchema = mongoose.Schema({
  orderNo: String, // 申请编号
  applyType: Number, // 申请类型   1: '事假', 2: '调休', 3: '年假'
  startTime: { type: Date },
  endTime: { type: Date },
  applyUser: {
    // 申请人
    userId: Number,
    userName: String,
    userEmail: String,
  },
  leaveTime: String, // 休假时长
  reasons: String, // 休假原因
  auditUsers: String, // 需要经过的审批人
  curAuditUserName: String, // 当前的审批人
  auditFlows: [{ userId: Number, userName: String, userEmail: String }], // 审批流
  auditLogs: [{ userId: Number, userName: String, createTime: Date, remark: String, action: String }], // 审批日志
  applyState: { type: Number, default: 1 }, //审批状态  1: '待审批', 2: '审批中', 3: '审批拒绝', 4: '审批通过', 5: '作废'
  createTime: { type: Date, default: Date.now() },
  updateTime: { type: Date, default: Date.now() }, //更新时间
});

// 模型名称 ， schema，数据库
module.exports = mongoose.model('leave', leaveSchema, 'leaves');
